# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     viewsets
   Description :
   Author :       tomtoto
   date：          2018/8/21
-------------------------------------------------
   Change Activity:
                   2018/8/21:
-------------------------------------------------
"""
from django.contrib.auth.models import Group
from rest_framework import viewsets
from .serializers import GroupSerializer
from rest_framework.permissions import IsAdminUser,AllowAny,IsAuthenticatedOrReadOnly,IsAuthenticated

# ViewSets define the view behavior.
class GroupViewSet(viewsets.ModelViewSet):
#class UserViewSet(mixins.ListModelMixin, mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, viewsets.GenericViewSet):
    """
    retrieve:
        Return a group instance.
    list:
        Return all groups, ordered by most recently joined.
    create:
        Create a new group.
    delete:
        Remove an existing group.
    partial_update:
        Update one or more fields on an existing group.
    update:
        Update a group.
    """

    queryset = Group.objects.all()
    serializer_class = GroupSerializer
    permission_classes = (IsAuthenticatedOrReadOnly,)
    filter_fields = ('id', 'name')
    lookup_field = 'id'